/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package framework.model;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ThanhNguyen
 */
public abstract class Customer implements ICustomer {

    private String name;

    public String getName() {
        return name;
    }
    private String email;
    Address addr;
    private List<Account> accounts;

    public Customer(String name, String email, Address address) {
        this.name = name;
        this.addr = address;

        this.accounts = new ArrayList<Account>();
    }

    public void addAccount(Account a) {
        accounts.add(a);
    }

    public void sendNotification(String msg) {
        System.out.println("Sent Notification: " + msg);
    }

    public abstract String getType();

    public String getField(String key) {
        switch (key) {
            case Constant.A_NAME:
                return name;
            case Constant.A_EMAIL:
                return email;
            case Constant.A_STREET:
                return addr.street;
            case Constant.A_CITY:
                return addr.city;
            case Constant.A_STATE:
                return addr.state;
            case Constant.A_ZIP:
                return addr.zip;
            default:
                return null;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (o != null  && o instanceof String && ((String) o).equals(name)) {
            return true;
        }
        return super.equals(o); 
    }

    public void addInterest() {
        for (Account account : accounts) {
            account.addInterest();
        }
    }

    @Override
    public String toString() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Address getAddress() {
        return addr;
    }

    public String generateAccountsReport() {
        StringBuilder sb = new StringBuilder();
        for (Account account : accounts) {
            sb.append(account.generateMonthlyReport()).append('\n');
        }
        return sb.toString();
    }
}
